package com.corewillsoft.fireflies.gamelaws;

/**
 * @author "Vlad Sumtsov"
 */
import com.corewillsoft.fireflies.gameobjects.AreaObject;
import com.corewillsoft.fireflies.gameobjects.GameObject;

public abstract class BaseLaw {

	protected AreaObject influenceArea;
	protected GameObject parent;

	public abstract LawType getType();

	public abstract void applicate(GameObject gameObject);

	public void setArea(AreaObject objectArea) {
		this.influenceArea = objectArea;
	}

	public AreaObject getArea() {
		return this.influenceArea;
	}

	public boolean isInArea(GameObject gameObject) {
		boolean isInArea = false;
		if (influenceArea == null) {
			// if objectArea is undefined, this means any located gameObject
			// is in influence
			isInArea = true;
		} else {
			isInArea = influenceArea.isInArea(gameObject);
		}

		return isInArea;
	}

	public void setParent(GameObject gameObject) {
		this.parent = gameObject;
		setArea(gameObject.getArea());
	}

	public GameObject getParent() {
		return this.parent;
	}

	/**
	 * Initializes influence area of the particular law;
	 * by default, influence area of the law is equal to area of parent of this law
	 */
	public void initializeInfluenceArea() {
		if (parent == null) {
			setArea(null);
		} else {
			setArea(parent.getArea());
		}
	}

}
